<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
  Class: RubyMotionQuery::ImageUtils
  
    &mdash; Documentation by YARD 0.8.7.3
  
</title>

  <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />

  <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  hasFrames = window.top.frames.main ? true : false;
  relpath = '../';
  framesUrl = "../frames.html#!" + escape(window.location.href);
</script>


  <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>


  </head>
  <body>
    <div id="header">
      <div id="menu">
  
    <a href="../_index.html">Index (I)</a> &raquo;
    <span class='title'><span class='object_link'><a href="../RubyMotionQuery.html" title="RubyMotionQuery (module)">RubyMotionQuery</a></span></span>
     &raquo; 
    <span class="title">ImageUtils</span>
  

  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">
  
    <a class="full_list_link" id="class_list_link"
        href="../class_list.html">
      Class List
    </a>
  
    <a class="full_list_link" id="method_list_link"
        href="../method_list.html">
      Method List
    </a>
  
    <a class="full_list_link" id="file_list_link"
        href="../file_list.html">
      File List
    </a>
  
</div>
      <div class="clear"></div>
    </div>

    <iframe id="search_frame"></iframe>

    <div id="content"><h1>Class: RubyMotionQuery::ImageUtils
  
  
  
</h1>

<dl class="box">
  
    <dt class="r1">Inherits:</dt>
    <dd class="r1">
      <span class="inheritName"><span class='object_link'><a href="../Object.html" title="Object (class)">Object</a></span></span>
      
        <ul class="fullTree">
          <li><span class='object_link'><a href="../Object.html" title="Object (class)">Object</a></span></li>
          
            <li class="next">RubyMotionQuery::ImageUtils</li>
          
        </ul>
        <a href="#" class="inheritanceTree">show all</a>
      
      </dd>
    
  
  
    
  
    
  
  
  
    <dt class="r2 last">Defined in:</dt>
    <dd class="r2 last">motion/ruby_motion_query/image.rb</dd>
  
</dl>
<div class="clear"></div>


  <h2>Constant Summary</h2>
  
    <dl class="constants">
      
        <dt id="DEFAULT_IMAGE_EXT-constant" class="">DEFAULT_IMAGE_EXT =
          
        </dt>
        <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>png</span><span class='tstring_end'>'</span></span></pre></dd>
      
    </dl>
  







  
    <h2>
      Class Method Summary
      <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#from_view-class_method" title="from_view (class method)">+ (UIImage) <strong>from_view</strong>(view, use_content_size = false) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Note: FROM Sugarcube, thanks Sugarcube.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#resource-class_method" title="resource (class method)">+ (UIImage) <strong>resource</strong>(file_base_name, opts = {}) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#resource_for_device-class_method" title="resource_for_device (class method)">+ (UIImage) <strong>resource_for_device</strong>(file_base_name, opts = {}) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#resource_resizable-class_method" title="resource_resizable (class method)">+ (UIImage) <strong>resource_resizable</strong>(file_base_name, opts) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
    </ul>
  



  <div id="class_method_details" class="method_details_list">
    <h2>Class Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="from_view-class_method">
  
    + (<tt>UIImage</tt>) <strong>from_view</strong>(view, use_content_size = false) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>Note: FROM Sugarcube, thanks Sugarcube</p>

<p>Easily take a snapshot of a `UIView`.</p>

<p>Calling `from_view` with no arguments will return the image based on the
`bounds` of the image.  In the case of container views (notably
`UIScrollView` and its children) this does not include the entire contents,
which is something you probably want.</p>

<p>If you pass a truthy value to this method, it will use the `contentSize` of
the view instead of the `bounds`, and it will draw all the child views, not
just those that are visible in the viewport.</p>

<p>It is guaranteed that `true` and `:all` will always have this behavior.  In
the future, if this argument becomes something that accepts multiple
values, those two are sacred.</p>


  </div>
</div>
<div class="tags">
  
<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>UIImage</tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'motion/ruby_motion_query/image.rb', line 64</span>

<span class='kw'>def</span> <span class='id identifier rubyid_from_view'>from_view</span><span class='lparen'>(</span><span class='id identifier rubyid_view'>view</span><span class='comma'>,</span> <span class='id identifier rubyid_use_content_size'>use_content_size</span> <span class='op'>=</span> <span class='kw'>false</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_scale'>scale</span> <span class='op'>=</span> <span class='const'>UIScreen</span><span class='period'>.</span><span class='id identifier rubyid_mainScreen'>mainScreen</span><span class='period'>.</span><span class='id identifier rubyid_scale'>scale</span>
  <span class='kw'>if</span> <span class='id identifier rubyid_use_content_size'>use_content_size</span>
    <span class='const'>UIGraphicsBeginImageContextWithOptions</span><span class='lparen'>(</span><span class='id identifier rubyid_view'>view</span><span class='period'>.</span><span class='id identifier rubyid_contentSize'>contentSize</span><span class='comma'>,</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='id identifier rubyid_scale'>scale</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_context'>context</span> <span class='op'>=</span> <span class='const'>UIGraphicsGetCurrentContext</span><span class='lparen'>(</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_view'>view</span><span class='period'>.</span><span class='id identifier rubyid_subviews'>subviews</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_subview'>subview</span><span class='op'>|</span>
      <span class='const'>CGContextSaveGState</span><span class='lparen'>(</span><span class='id identifier rubyid_context'>context</span><span class='rparen'>)</span>
      <span class='const'>CGContextTranslateCTM</span><span class='lparen'>(</span><span class='id identifier rubyid_context'>context</span><span class='comma'>,</span> <span class='id identifier rubyid_subview'>subview</span><span class='period'>.</span><span class='id identifier rubyid_frame'>frame</span><span class='period'>.</span><span class='id identifier rubyid_origin'>origin</span><span class='period'>.</span><span class='id identifier rubyid_x'>x</span><span class='comma'>,</span> <span class='id identifier rubyid_subview'>subview</span><span class='period'>.</span><span class='id identifier rubyid_frame'>frame</span><span class='period'>.</span><span class='id identifier rubyid_origin'>origin</span><span class='period'>.</span><span class='id identifier rubyid_y'>y</span><span class='rparen'>)</span>
      <span class='id identifier rubyid_subview'>subview</span><span class='period'>.</span><span class='id identifier rubyid_layer'>layer</span><span class='period'>.</span><span class='id identifier rubyid_renderInContext'>renderInContext</span><span class='lparen'>(</span><span class='id identifier rubyid_context'>context</span><span class='rparen'>)</span>
      <span class='const'>CGContextRestoreGState</span><span class='lparen'>(</span><span class='id identifier rubyid_context'>context</span><span class='rparen'>)</span>
    <span class='kw'>end</span>
    <span class='id identifier rubyid_image'>image</span> <span class='op'>=</span> <span class='const'>UIGraphicsGetImageFromCurrentImageContext</span><span class='lparen'>(</span><span class='rparen'>)</span>
    <span class='const'>UIGraphicsEndImageContext</span><span class='lparen'>(</span><span class='rparen'>)</span>
  <span class='kw'>else</span>
    <span class='const'>UIGraphicsBeginImageContextWithOptions</span><span class='lparen'>(</span><span class='id identifier rubyid_view'>view</span><span class='period'>.</span><span class='id identifier rubyid_bounds'>bounds</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span><span class='comma'>,</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='id identifier rubyid_scale'>scale</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_view'>view</span><span class='period'>.</span><span class='id identifier rubyid_layer'>layer</span><span class='period'>.</span><span class='id identifier rubyid_renderInContext'>renderInContext</span><span class='lparen'>(</span><span class='const'>UIGraphicsGetCurrentContext</span><span class='lparen'>(</span><span class='rparen'>)</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_image'>image</span> <span class='op'>=</span> <span class='const'>UIGraphicsGetImageFromCurrentImageContext</span><span class='lparen'>(</span><span class='rparen'>)</span>
    <span class='const'>UIGraphicsEndImageContext</span><span class='lparen'>(</span><span class='rparen'>)</span>
  <span class='kw'>end</span>
  <span class='id identifier rubyid_image'>image</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="resource-class_method">
  
    + (<tt>UIImage</tt>) <strong>resource</strong>(file_base_name, opts = {}) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    

  </div>
</div>
<div class="tags">
  
<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>UIImage</tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


24
25
26
27
28
29
30
31
32
33
34
35
36</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'motion/ruby_motion_query/image.rb', line 24</span>

<span class='kw'>def</span> <span class='id identifier rubyid_resource'>resource</span><span class='lparen'>(</span><span class='id identifier rubyid_file_base_name'>file_base_name</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_ext'>ext</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:ext</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='const'>DEFAULT_IMAGE_EXT</span>
  <span class='id identifier rubyid_cached'>cached</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:cached</span><span class='rbracket'>]</span>
  <span class='id identifier rubyid_cached'>cached</span> <span class='op'>=</span> <span class='kw'>true</span> <span class='kw'>if</span> <span class='id identifier rubyid_cached'>cached</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>

  <span class='kw'>if</span> <span class='id identifier rubyid_cached'>cached</span>
    <span class='const'>UIImage</span><span class='period'>.</span><span class='id identifier rubyid_imageNamed'>imageNamed</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_file_base_name'>file_base_name</span><span class='rbrace'>}</span><span class='tstring_content'>.</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_ext'>ext</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> 
  <span class='kw'>else</span>
    <span class='id identifier rubyid_file_base_name'>file_base_name</span> <span class='op'>&lt;&lt;</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>@2x</span><span class='tstring_end'>'</span></span> <span class='kw'>if</span> <span class='const'>RMQ</span><span class='period'>.</span><span class='id identifier rubyid_device'>device</span><span class='period'>.</span><span class='id identifier rubyid_retina?'>retina?</span>
    <span class='id identifier rubyid_file'>file</span> <span class='op'>=</span> <span class='const'>NSBundle</span><span class='period'>.</span><span class='id identifier rubyid_mainBundle'>mainBundle</span><span class='period'>.</span><span class='id identifier rubyid_pathForResource'>pathForResource</span><span class='lparen'>(</span><span class='id identifier rubyid_file_base_name'>file_base_name</span><span class='comma'>,</span> <span class='label'>ofType:</span> <span class='id identifier rubyid_ext'>ext</span><span class='rparen'>)</span>
    <span class='const'>UIImage</span><span class='period'>.</span><span class='id identifier rubyid_imageWithContentsOfFile'>imageWithContentsOfFile</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span><span class='rparen'>)</span>
  <span class='kw'>end</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="resource_for_device-class_method">
  
    + (<tt>UIImage</tt>) <strong>resource_for_device</strong>(file_base_name, opts = {}) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    

  </div>
</div>
<div class="tags">
  
<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>UIImage</tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


19
20
21</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'motion/ruby_motion_query/image.rb', line 19</span>

<span class='kw'>def</span> <span class='id identifier rubyid_resource_for_device'>resource_for_device</span><span class='lparen'>(</span><span class='id identifier rubyid_file_base_name'>file_base_name</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_resource'>resource</span><span class='lparen'>(</span> <span class='const'>RMQ</span><span class='period'>.</span><span class='id identifier rubyid_device'>device</span><span class='period'>.</span><span class='id identifier rubyid_four_inch?'>four_inch?</span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_file_base_name'>file_base_name</span><span class='rbrace'>}</span><span class='tstring_content'>-568h</span><span class='tstring_end'>&quot;</span></span> <span class='op'>:</span> <span class='id identifier rubyid_file_base_name'>file_base_name</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="resource_resizable-class_method">
  
    + (<tt>UIImage</tt>) <strong>resource_resizable</strong>(file_base_name, opts) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    

  </div>
</div>
<div class="tags">
  
<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>UIImage</tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


39
40
41
42
43
44</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'motion/ruby_motion_query/image.rb', line 39</span>

<span class='kw'>def</span> <span class='id identifier rubyid_resource_resizable'>resource_resizable</span><span class='lparen'>(</span><span class='id identifier rubyid_file_base_name'>file_base_name</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='rparen'>)</span>
  <span class='comment'># TODO, also alloow short syntax, t: instead of top: etc
</span>  <span class='id identifier rubyid_ext'>ext</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:ext</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='const'>DEFAULT_IMAGE_EXT</span>
  <span class='id identifier rubyid_image'>image</span> <span class='op'>=</span> <span class='id identifier rubyid_resource'>resource</span><span class='lparen'>(</span><span class='id identifier rubyid_file_base_name'>file_base_name</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_image'>image</span><span class='period'>.</span><span class='id identifier rubyid_resizableImageWithCapInsets'>resizableImageWithCapInsets</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:top</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:left</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:bottom</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:right</span><span class='rbracket'>]</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>resizingMode:</span> <span class='const'>UIImageResizingModeStretch</span><span class='rparen'>)</span> 
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>

    <div id="footer">
  Generated on Sun Dec  8 20:15:51 2013 by
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.8.7.3 (ruby-1.9.3).
</div>

  </body>
</html>